//
//  FontButton.m
//  ShareBoard
//
//  Created by lidi on 2018/6/12.
//  Copyright © 2018年 曹雪莹. All rights reserved.
//

#import "FontButton.h"
#import <Masonry.h>

@interface FontButton()
@property(nonatomic,strong)UIImageView *icon;
@end

@implementation FontButton

- (instancetype)initWith:(NSInteger)index title:(NSString *)title
{
    self = [super init];
    if (self) {
        UIView *line = [UIView new];
        line.backgroundColor = [UIColor lightGrayColor];
        [self addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            if (index == 0) {
                make.width.equalTo(line.superview.mas_width).dividedBy(2);
                make.right.equalTo(line.superview);
            } else if (index == 4) {
                make.width.equalTo(line.superview.mas_width).dividedBy(2);
                make.left.equalTo(line.superview);
            } else {
                make.left.right.equalTo(line.superview);
            }
            make.centerY.equalTo(line.superview).offset(-10.0f);
            make.height.equalTo(@2.0f);
        }];
        
        self.icon = [UIImageView new];
        self.icon.image = [UIImage imageNamed:@"pop_font_point"];
        self.icon.contentMode = UIViewContentModeCenter;
        [self addSubview:self.icon];
        [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.icon.superview).offset(-10.0f);
            make.centerX.equalTo(self.icon.superview);
            make.size.mas_equalTo(CGSizeMake(20.0f, 20.0f));
        }];
        
        UILabel *labelTitle = [UILabel new];
        labelTitle.font = [UIFont systemFontOfSize:14.0f weight:UIFontWeightLight];
        labelTitle.text = title;
        [self addSubview:labelTitle];
        [labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(labelTitle.superview);
            make.bottom.equalTo(labelTitle.superview).offset(-15.0f);
        }];
    }
    return self;
}

- (void)setSelected:(BOOL)selected {
    _selected = selected;
    if (selected) {
        self.icon.image = [UIImage imageNamed:@"pop_font_cpoint"];
    } else {
        self.icon.image = [UIImage imageNamed:@"pop_font_point"];
    }
}

@end
